package com.ccz.demo.design.subscribe;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName ConcreteSubject
 * @Author caihaoyun
 * @Date 2020/4/2
 * @Version V1.0
 * 具体主题
 **/
public class ConcreteSubject implements Star{

    // 保存所有粉丝
    private List<Fan> fanList = new ArrayList<>();

    @Override
    public void addFans(Fan fan) {
        fanList.add(fan);
    }

    @Override
    public void delFans(Fan fan) {
        fanList.remove(fan);
    }

    @Override
    public void notify(String message) {
        for (Fan fan : fanList) {
            fan.update(message); // 通知消息
        }
    }
}
